package agh.sr.lab4.common.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Properties;

public class ClientUtils {

	public String extractConnectionInfoFromProperty(String[] args,
			String propertyKey) throws FileNotFoundException, IOException {

		String fileName = "";
		String fileNameKey = "--Ice.Config=";

		for (String param : args) {
			if (param.contains(fileNameKey)) {
				fileName = param.substring(fileNameKey.length());
				break;
			}
		}

		Properties prop = new Properties();
		prop.load(new FileInputStream(fileName));
//		String value = prop.getProperty(propertyKey);
//		String regex = "[a-zA-Z0-9]*[^:]";
//		String[] tokens = value.split(regex);
//		System.out.println(Arrays.toString(tokens));
//		System.out.println(value);
//		System.out.println(regex);
//BankManagerServant:tcp -h 127.0.0.1 -p 10000
//		System.out.println(tokens.length);
		return prop.getProperty("serverEP");
//		return tokens[1];

	}

	public String generateConnectionStringToProxy(String proxyName,
			String connectionInfo) {
		return proxyName + connectionInfo;

	}
}
